/**
 * AUTO_COPYRIGHT_SUB_TAG
 */
package com.rim.samples.device.push.cmd;

import screens.Controller;

import com.rim.samples.device.push.ContentProviderProtocol;
import com.rim.samples.device.push.PersistentStorage;
import com.rim.samples.device.push.lib.BpasProtocol;
import com.rim.samples.device.push.lib.PushLibFactory;

public class RegisterCommand extends NetworkCommand {
    
    private boolean isEnterprise;

    public RegisterCommand( String username, String password, boolean isEnterprise ) {
        super( username, password );
        this.isEnterprise = isEnterprise;
    }

    protected void execute() throws Exception {
        // first we register with Content Provider
        ContentProviderProtocol.performCommand( ContentProviderProtocol.CMD_SUBSCRIBE, username, password, isEnterprise, tx );
        // if the registration is successful we register with BPS
        BpasProtocol bpasProtocol = PushLibFactory.getBpasProtocol();
        bpasProtocol.register( tx, isEnterprise );
        // update the registered state
        PersistentStorage.setRegistered( true );
        Controller.getInstance().setPushStatus(true);
    }

    public String getCommandName() {
        return "register";
    }

}
